﻿@model Method
@{
    var methodId = ViewBag.methodId;
    var categoryId = ViewBag.categoryId;
    var templateClass = ViewBag.templateClass;
}
<div class="head_blue_bar">
    <div class="head_src w1170">
        <span>@Html.ActionLink("文檔中心", "Index", "Home", new { Th.ProjectId }, null) >@Html.ActionLink("API", "Index", "Home", new { Th.ProjectId }, null)> @Model.Name </span>
    </div>
</div>
<div class="blank30px"></div>
<div class="con_box w1170">
    <!--左侧-->
    <!--js動態加載-->
    <div id="leftMenu"></div>
    <!--左側-->
    <!--右侧-->
    <div class="con_right right">
        <div class="con_mtl_table">


            <div class="apidetail_con1">
                <dl>
                    <dt>
                        @Model.Name
                    </dt>
                </dl>
                <dl>
                    <dt>
                        <a class="red" target="_blank" href="@Url.Action("Edit","Method",new{Area="Admin",Th.ProjectId,Id=Model.Id})">後台修改</a>
                    </dt>
                </dl>
                <dl>
                    <dt>URL</dt>
                    <dd>@Model.Url</dd>
                </dl>

                <dl>
                    <dt>支援格式</dt>
                    <dd>@Model.SupportFomats</dd>
                </dl>

                <dl>
                    <dt>HTTP請求方式</dt>
                    <dd>@(Model.HttpMethod == MethodType.Get ? "Get" : "Post")</dd>
                </dl>

                <dl>
                    <dt>是否需要登錄</dt>
                    <dd>@(Model.IsNeedLogin ? "是" : "否")</dd>
                </dl>

                <dl>
                    <dt>訪問授權限制</dt>
                    <dd>
                        访问级别：<b>普通接口</b><br>
                        频次限制：<b>@(Model.IsTimeLimit ? "是" : "否")</b>
                    </dd>
                </dl>
            </div>
            <div class="apidetail_con2" id="questions">
                <h2 class="con_title1">请求参数</h2>
                <ul>
                    <li class="clearfix">
                        <h5><b class="UI-ask"></b>請求參數</h5>
                        <div class="foldContent">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="con_table">
                                <thead>
                                    <tr>
                                        <th>名稱</th>
                                        <th>類型</th>
                                        <th>是否必須 </th>
                                        <th>默認值</th>
                                        <th>描述</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var item in Model.Parameters.Where(s => s.Type == ParameterType.Query))
                                    {
                                        <tr>
                                            <td>@item.Name</td>
                                            <td>@item.DataType</td>
                                            <td>@item.IsRequired</td>
                                            <td>@item.DefaultValue</td>
                                            <td>@Html.CusRaw(item.Description)</td>
                                        </tr>
                                    }
                                    <tr>
                                        <td colspan="5">
                                            <pre>
                                                @foreach (var item in Model.Parameters.Where(s => s.Type == ParameterType.Query))
                                                {
                                                    var defaultValue = (item.DefaultValue ?? "").ToString();
                                                    if (!string.IsNullOrEmpty(defaultValue))
                                                    {
                                                        if (item.DataType.ToLower() == "string")
                                                        {
                                                            defaultValue = string.Format(" = {0};", defaultValue);
                                                        }
                                                        else
                                                        {
                                                            defaultValue = string.Format(" = {0} ;", defaultValue);
                                                        }
                                                    }
                                                    
                                                    @:///&lt;summary&gt;                                                    
                                                    @:///@item.DescriptionIgnorHtml
                                                    @:///&lt;/summary&gt;
                                                    @:public @Html.Raw(item.DataType.ToLower()) @Html.Raw(item.Name)  {get;set;} @defaultValue
                                                }
                                            </pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </li>
                    <li class="clearfix">
                        <h5><b class="UI-ask"></b>接口描述</h5>
                        <div class="foldContent">
                            <span class="red">@Html.CusRaw(Model.Description)</span>
                        </div>
                    </li>
                    <li class="clearfix">
                        <h5><b class="UI-ask"></b>返回字段說明</h5>
                        <div class="foldContent">
                            @Html.CusRaw(Model.ResultDesc)
                        </div>
                    </li>
                    <li class="clearfix">
                        <h5><b class="UI-ask"></b>返回数据示例</h5>
                        <div class="foldContent container">
                            @Html.CusRaw(Model.ResultDemo)
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!--右側-->
</div>

@section script{
    <script>
        $(function () {
            getLeft();
        });
        function getLeft() {
            var data = {projectId:@Th.ProjectId,categoryId:@categoryId};
            $.getJSON('@Url.Action("getleft")',data,function(json){
                $("#leftMenu").html($("#leftTemp").render(json));
                setLeftActive();

            });
        }

        //改變選中菜單的顏色
        function setLeftActive() {
            var cId = parseInt('@methodId')
            if (isNaN(cId)) {
                $('#leftMenu').find('a:eq(0)').addClass('act2');
            } else {
                $('#leftMenu').find('.act2').removeClass('act2');
                $('#leftMenu').find('a[mid="' + cId + '"]').addClass('act2');
            }
        }
    </script>

    <script type="text/x-jsrender" id="leftTemp">
        <div class="con_left left">
            <h3 class="menu_title">{{:Name}}</h3>
            <ul class="menu_1" id="CategoryList">
                {{for Methods}}
                <li {{if Url.indexOf('/')==-1}} style="background:red" {{/if}}>
                    <a title="{{:Name}}" mid="{{:Id}}" href="@Url.Action("Detail","Method",new {Th.ProjectId})&categoryId={{:CategoryId}}&methodId={{:Id}}">{{:Name}}<br />{{:Url}}</a>
                </li>
                {{/for}}
            </ul>

            {{for Categorys}}
            <h3 class="menu_title">
                <a title="{{:Name}}" {{if method.Id>0}} href="@Url.Action("Detail","Method",new {Th.ProjectId})&categoryId={{:Id}}&methodId={{:method.Id}}" {{/if}}>{{:Name}}</a>
            </h3>
            {{/for}}
            <div class="clear"></div>
        </div>
    </script>
}